<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/base.css" />
		<link rel="stylesheet" type="text/css" href="css/my_register.css"/>
		<script src="js/jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<div id="wu_quan">
			<div id="header">
				<!-- logo -->
				<a href="#" id="logo"><img src="img/logo.png"></a>
				<div id="navmenu">
					<nav id="menu">
						<ul>
							<li >
								<a href="index.html">首页</a>
							</li>
							<li >
								<a href="productlist.html">买车</a>
							</li>
							<li>
								<a href="">卖车</a>
							</li>
							<li>
								<a href="xinche.html">新车</a>
							</li>
							<li >
								<a href="baodian.html">宝典</a>
							</li>
							<li>
								<a href="fwbz.html">服务保障</a>
							</li>
							<li >
								<a href="my_reg.html">注册</a>
							</li>
							<li class="active">
								<a href="my_register.html">登录</a>
							</li>
						</ul>
					</nav>
					<div id="search">
						<form role="search" method="get">
							<input type="text" placeholder="search..." name="s" value="" autocomplete="off" />
						</form>
					</div>
				</div>
			</div>
			<br><br><br><br><br><br><br><br><br>
			<br><br>
			<div style="text-align:center;clear:both">
			</div>
		</div>
		<div id="wu_zong">
			<div id="my_zhuce">
				<div class="zhuce_right">
					<div class="zhuce_div">
						<form>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr class="t1">
									<td id="zc"> 登录</td>
								</tr>
								<tr>
									<td colspan="2"><input type="text" id="username" value="" placeholder="用户名" /></td>
								</tr>
								<tr>
									<td colspan="2"><input type="password" id="pwd" value="" placeholder="请输入密码" /></td>
								</tr>
								<tr>
									<td colspan="2"><input type="button" id="zhuce" value="立即登录" onclick="login()" /></td>
								</tr>
								<!--<tr class="t2">
									<td colspan="2"><input type="checkbox" id="denglu" />自动登录</td>
								</tr>-->
							</table>
						</form>
					</div>
				</div>
			</div>
		</div>
		<div id="wu_foot">
			<div id="wu_foot_foot">
				<ul>
					<li>
						<a href="#">关于我们</a>
					</li>
					<li>
						<a href="#">加入我们</a>
					</li>
					<li>
						<a href="#">帮助中心</a>
					</li>
					<li>
						<a href="#">用户反馈</a>
					</li>
					<li>
						<a href="#">商家申请</a>
					</li>
					<li>
						<a href="#">鹏鹏易购</a>
					</li>
					<li>
						<a href="#">网站地图</a>
					</li>
					<div class="fr m10">
						<img src="img/code.jpg" />
						<p class="f16">微信公众号</p>
						<p class="f13">微信动态早知道</p>
					</div>
					<div class="fr m10">
						<img src="img/code.jpg" />
						<p class="f16">APP下载</p>
						<p class="f13">车源更新不错过</p>
					</div>
				</ul>
			</div>
		</div>
		<script src="js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(function() {
				if($.cookie("userSession")) {
					$.ajax({
						type: "get",
						url: "https://api.leancloud.cn/1.1/users/me",
						async: true,
						headers: {
							"X-LC-Id": "9keh2YX5j8hpDc0YR2REhv0q-gzGzoHsz",
							"X-LC-Key": "rrdO8OEJACH5qna3m3FzhpYf",
							"X-LC-Session": $.cookie("userSession")
						},
						success: function(data) {
							location.href="index.html";
						},
						error: function(e) {
							var code = JSON.parse(e.responseText).code;
							console.log(code);
							for(var i in errocode) {
								if(errocode[i].code == code) {
									console.log(errocode[i].content)
								}
							}
						}
					});
				}
			});
			$(function() {
				var username = getUrlItem(location.search, "username");
				$("#username").val(username);
				//获取url内的username
				function getUrlItem(url, name) {
					start = url.indexOf(name + "=");
					if(start != -1) {
						start = start + name.length + 1
						c_end = url.indexOf("&", start)
						if(c_end == -1) c_end = url.length
						return unescape(url.substring(start, c_end))
					}
					return '';
				}
			});

			function login() {
				var username = $("#username").val();
				var pwd = $("#pwd").val();
				$.ajax({
					type: "post",
					url: "https://api.leancloud.cn/1.1/login",
					headers: {
						"X-LC-Id": "9keh2YX5j8hpDc0YR2REhv0q-gzGzoHsz",
						"X-LC-Key": "rrdO8OEJACH5qna3m3FzhpYf",
						"Content-Type": "application/json"
					},
					data:'{"username":"'+username+'","password":"'+pwd+'"}',
					success:function(data){
						console.log("登陆成功");
						console.log(data.sessionToken);
						$.cookie("userSession",data.sessionToken, {expires: 1});
						location.href="index.html";
					},
					error: function(e) {
					var code = JSON.parse(e.responseText).code;
					console.log(code);
					for(var i in errocode) {
						if(errocode[i].code == code) {
							console.log(errocode[i].content)
						}
					}
				}
				});
			}
		</script>
	</body>

</html>